#include "comm.hpp"
#include "fifo.hpp"

int main()
{
    Init init;
    int shmid = CreateShm();
    log(Debug, "create shm done");
    sleep(5);

    char *shadd = (char *)shmat(shmid, nullptr, 0);
    log(Debug, "attach shm done");

    int fd = open(FIFO_FILE, O_WRONLY);
    if (fd < 0)
    {
        log(Fatal, "open fail! %s", strerror(errno));
        exit(1);
    }

    int cnt = 3;
    char c = 'c';
    while (cnt--)
    {
        cout << "@Please Enter:";
        fgets(shadd, 4096, stdin);
        write(fd, &c, 1);
    }

    sleep(3);
    shmdt(shadd);
    log(Debug, "detach shm done");

    sleep(3);
    shmctl(shmid, IPC_RMID, nullptr);
    log(Debug, "destroy shm done");

    return 0;
}